package com.tianyadu.mmall.core.validate.code.service.impl;

import com.tianyadu.mmall.core.validate.code.ImageCode;
import com.tianyadu.mmall.core.validate.code.service.AbstractValidateCodeProcessor;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import javax.imageio.ImageIO;

/**
 * @author xueyj
 * @date 2019-11-14 00:29
 */
@Component
public class ImageValidateCodeProcessor extends AbstractValidateCodeProcessor<ImageCode> {

    /**
     * 发送校验码，由子类实现
     *
     * @param request   spring工具类，封装请求/响应信息
     * @param imageCode 图片验证码信息
     * @return void
     * @author xueyj
     * @date 2019/11/14-0:29
     */
    @Override
    protected void send(@NotNull ServletWebRequest request, @NotNull ImageCode imageCode) throws Exception {
        ImageIO.write(imageCode.getImage(), "JPEG", request.getResponse().getOutputStream());
    }
}